<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<style>
    .clickMe_form {
        margin-left: 770px;
        cursor: pointer;
        color: #1C98FF;
    }
</style>
<form:form commandName="logs" cssClass="form-horizontal" role="form" onsubmit="return false;">
    <p style="font-weight: bold; font-size: 18px;">
        <span class="glyphicon glyphicon-bookmark" style="color: #0072ff;">
        </span> 项目基本情况:
    </p>
    <div class="form-group">
        <label class="col-sm-1 control-label no-padding-right" for="taskName">任务名称</label>
        <div class="col-sm-5">
            <input type="text" name="taskName" id="taskName" placeholder="任务名称" readonly="readonly"
                   value="${task.taskName}" class="form-control ">
        </div>
        <label class="col-sm-1 control-label no-padding-right" for="projectName">项目名称</label>
        <div class="col-sm-5">
            <input type="text" name="projectName" id="projectName" placeholder="项目名称" readonly="readonly"
                   value="${task.projectName}" class="form-control ">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label no-padding-right" for="taskContent">任务内容</label>
        <div class="col-sm-11">
            <textarea rows="1" id="taskContent" name="taskContent" readonly="readonly" placeholder="任务内容"
                      class="form-control ">${task.taskContent}</textarea>
        </div>
    </div>
    <c:if test="${not empty bnpUser}">
        <c:if test="${bnpUser.branchType == '4'}">
            <hr width="100%;height:2px;" style="border-top: 1px solid #aaa;">
            <p style="font-weight: bold; font-size: 18px;">
                <span class="glyphicon glyphicon-bookmark" style="color: #0072ff;">
                </span> 添加催办记录:
            </p>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right" for="task-methon-id">督查方式</label>
                <div class="col-sm-5">
                    <select name="methonCode" class="form-control " style="width: 100%"
                            data-placeholder="督查方式" id="task-methon-id" required>
                        <option value="">请选择您本次的督查方式</option>
                        <c:forEach items="${methods}" var="methods">
                            <option value="${methods.methonCode }">${methods.methonName }</option>
                        </c:forEach>
                    </select>
                </div>
                <label class="col-sm-1 control-label no-padding-right">节点情况</label>
                <div class="col-sm-5">
                    <input type="text" name="supervision-Result" id="supervision-Result" readonly="readonly"
                           class="form-control ">
                </div>
                    <%--<label class="col-sm-1 control-label no-padding-right">督查日期</label>--%>
                    <%--<div class="col-sm-5">--%>
                    <%--<input type="text" name="datatime" class="form-control date-upd date-picker"--%>
                    <%--placeholder="点击选择时间" required/>--%>
                    <%--</div>--%>
            </div>
            <%--<div class="form-group">--%>
            <%--<label class="col-sm-2 control-label no-padding-right" for="taskContent">*督查记录:</label>--%>
            <%--<div class="col-sm-10">--%>
            <%--<textarea rows="3" name="record" class="form-control"--%>
            <%--placeholder="请填写催办记录" required/>--%>
            <%--</div>--%>
            <%--</div>--%>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right" for="supervisionAsk">督查情况</label>
                <div class="col-sm-11">
            <textarea rows="3" id="supervisionAsk" name="supervisionAsk" class="form-control"
                      placeholder="请填写督查情况" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">佐证材料</label>
                <div class="col-sm-3">
                    <input type="file" id="fileupload1" name="files"/>
                </div>
                <button class="col-sm-2 btn btn-large btn-primary" id="btn-upload1">上传</button>
                <input type="text" name="taxproof" id="taxproof_proof1"
                       class="form-control " style="display: none"/>
                <div class="col-sm-6">
                    <div class=" pull-right">
                        <button class=" btn btn-large btn-success" onclick="addCB()">添加催办记录</button>
                    </div>
                </div>
            </div>
            <hr width="100%;height:2px;" style="border-top: 1px solid #aaa;">
        </c:if>
        <c:if test="${bnpUser.branchType == '0' || bnpUser.branchType == '1'}">
            <hr width="100%;height:2px;" style="border-top: 1px solid #aaa;">
            <p style="font-weight: bold; font-size: 18px;">
                <span class="glyphicon glyphicon-bookmark" style="color: #0072ff;">
                </span> 添加完成情况:
            </p>
            <div class="form-group">
                <%--<label class="col-sm-1 control-label no-padding-right">选择日期</label>--%>
                <%--<div class="col-sm-5">--%>
                    <%--<input placeholder="点击选择时间" type="text" name="datatime"--%>
                           <%--class="form-control date-picker" required/>--%>
                <%--</div>--%>
                <label class="col-sm-1 control-label no-padding-right" for="resp-Result">节点情况</label>
                <div class="col-sm-5">
                    <input type="text" name="resp-Result" id="resp-Result" readonly="readonly"
                           class="form-control ">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right" for="taskContent">完成情况</label>
                <div class="col-sm-11">
			<textarea rows="3" name="record" placeholder="请填写完成情况"
                      class="form-control" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">佐证材料</label>
                <div class="col-sm-3">
                    <input type="file" id="fileupload2" name="files"/>
                </div>
                <button class="col-sm-2 btn btn-large btn-primary" id="btn-upload2">上传</button>
                <input type="text" name="taxproof" id="taxproof_proof2"
                       class="form-control " style="display: none"/>
                <div class="col-sm-6">
                    <div class=" pull-right">
                        <button class=" btn btn-large btn-success" onclick="addWC()">添加完成情况</button>
                    </div>
                </div>

            </div>
            <div class="form-group">
                <div class="col-sm-11">
                    <div class=" pull-right">
                    </div>
                </div>
            </div>
            <hr width="100%;height:2px;" style="border-top: 1px solid #aaa;">
        </c:if>
    </c:if>

    <c:if test="${empty logs}">
        <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" style="color: #761c19">无督查过程日志！</label>
        </div>
    </c:if>
    <c:if test="${not empty logs}">
        <p style="font-weight: bold; font-size: 18px;">
                <span class="glyphicon glyphicon-bookmark" style="color: #0072ff;">
                </span> 督查过程日志(按照时间先后顺序排序):
        </p>
    </c:if>
    <c:forEach items="${logs}" var="logs">
        <c:if test="${empty logs.supervisionTeamId}">
            <%--督查记录--%>
            <p style="font-size: 18px; color: #ff9e3a;">
                <span class="glyphicon glyphicon-record" style="color: #ff9e3a;">
                </span> 督查组督查记录：
            </p>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">日志时间</label>
                <div class="col-sm-3">
                    <input type="text" value="${logs.createDate} ${logs.createTime}" readonly="readonly"
                           class="form-control">
                </div>
                <label class="col-sm-1 control-label no-padding-right">督查方式</label>
                <div class="col-sm-3">
                    <input type="text" title="${logs.methonName}" value="${logs.methonName}" readonly="readonly"
                           placeholder="" class="form-control">
                </div>
                <div class="col-sm-2">
                    <button type="button" class="btn btn-sm btn-primary downloadFile" data-id="${logs.taxproof}"
                            style="width: 100%;">下载附件
                    </button>
                </div>
            </div>
            <div class="form-group">
                    <%--<label class="col-sm-1 control-label no-padding-right">督查记录</label>--%>
                    <%--<div class="col-sm-5">--%>
                    <%--<textarea rows="3" class="form-control" placeholder="请输入项目进展"--%>
                    <%--readonly="readonly">${logs.record}</textarea>--%>
                    <%--</div>--%>
                <label class="col-sm-1 control-label no-padding-right">督查情况</label>
                <div class="col-sm-11">
                    <textarea rows="3" class="form-control" placeholder="督查要求"
                              readonly="readonly">${logs.supervisionAsk}</textarea>
                </div>
            </div>
            <hr width="100%;height:2px;">
        </c:if>
        <c:if test="${not empty logs.supervisionTeamId}">
            <%--完成情况--%>
            <p style="font-size: 18px; color: #0072ff;">
                <span class="glyphicon glyphicon-record" style="color: #0072ff;">
                </span> 责任单位反馈记录：
            </p>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">日志时间</label>
                <div class="col-sm-3">
                    <input type="text" value="${logs.createDate} ${logs.createTime}"
                           placeholder="" readonly="readonly" class="form-control ">
                </div>
                <div class="col-sm-2">
                    <button type="button" class="btn btn-sm btn-primary downloadFile" data-id="${logs.taxproof}"
                            style="width: 100%;">下载附件
                    </button>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">完成情况</label>
                <div class="col-sm-11">
                    <textarea rows="3" readonly="readonly" placeholder=""
                              class="form-control ">${logs.record}</textarea>
                </div>
            </div>
            <hr width="100%;height:2px;">
        </c:if>
    </c:forEach>
    <h4 class="clickMe_form">历史记录∨</h4>
    <div class="open-sibling" hidden>
        <hr width="100%;height:2px;">
        <c:if test="${not empty listRecords}">
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right formsHead"
                       for="taskContent">责任单位反馈情况:</label>
            </div>
        </c:if>
        <c:forEach items="${listRecords}" var="listRecords">
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">反馈时间</label>
                <div class="col-sm-3">
                    <input type="text" value="${listRecords.createDate} ${listRecords.createTime}"
                           placeholder="" readonly="readonly" class="form-control ">
                </div>
                <div class="col-sm-3">
                    <button class="btn btn-sm btn-primary downloadFile" data-id="${listRecords.taxproof}"
                            style="width: 100%;">
                        下载附件
                    </button>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">完成情况</label>
                <div class="col-sm-11">
                    <textarea rows="3" class="form-control" readonly="readonly">${listRecords.record}</textarea>
                </div>
            </div>
            <hr width="100%;height:2px;">
        </c:forEach>
        <c:if test="${not empty supervisionLogs}">
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right formsHead" for="taskContent">督查组反馈情况:&nbsp;&nbsp;&nbsp;</label>
            </div>
        </c:if>
        <c:forEach items="${supervisionLogs}" var="logs">
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">督查日期</label>
                <div class="col-sm-3">
                    <input type="text" value="${logs.createDate} ${logs.createTime}" readonly="readonly"
                           class="form-control ">
                </div>

                <label class="col-sm-1 control-label no-padding-right">督查方式</label>
                <div class="col-sm-3">
                    <input type="text" value="${logs.methonName}" readonly="readonly"
                           placeholder="未填写" class="form-control">
                </div>

                <div class="col-sm-3">
                    <button class="btn btn-sm btn-primary downloadFile" data-id="${logs.taxproof}" style="width: 100%;">
                        下载附件
                    </button>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label no-padding-right">督查情况</label>
                <div class="col-sm-11">
                    <textarea rows="2" class="form-control" readonly="readonly">${logs.supervisionAsk}</textarea>
                </div>
            </div>
            <%--<div class="form-group">--%>
                <%--<label class="col-sm-1 control-label no-padding-right">督查记录</label>--%>
                <%--<div class="col-sm-11">--%>
                    <%--<textarea rows="2" class="form-control" readonly="readonly">${logs.record}</textarea>--%>
                <%--</div>--%>
            <%--</div>--%>
            <hr width="100%;height:2px;">
        </c:forEach>
    </div>
    <input type="text" name="sysId"  hidden value="${task.sysId}">
</form:form>
<div class="row" style="margin-left: 2px;">
    * 以上按住如此标志：<img src="/assets/web/img/zzc.png" alt="提示"/>可拖动调整相应输入框大小
</div>
<script src="<s:url value="/assets/js/ajaxfileupload.js"></s:url>"></script>
<script type="text/javascript">
    /**
     * 下载
     */
    $(".downloadFile").click(function () {
        var id = $(this).data("id");
        var url = "/communal/download/" + id;
        window.open(url);
    });
    //更新操作
    $("#showDetail").click(function () {
        showDetailView();
    });

    //非电话督查则需要上传材料（督查组）
    $("#task-methon-id").change(function () {
        var change = $("#task-methon-id").val();
        if (change == 'AA') {
            $("#fileupload1").removeAttr("required");
        } else {
            $("#fileupload1").attr("required", true);
        }
    });

    /**
     * 督查组上传材料
     */
    $("#btn-upload1").click(function () {
        var fileval = $("#fileupload1").val();
        if (fileval == null || fileval == "") {
            alert("未选择任何文件");
            return;
        }
        $(".shade").fadeIn(100);
        $(".warning").fadeIn(100);
        $('.la-square-jelly-box').show();
        showShade();
        //警告框自定义内容
        $('.warning>.title>em').html('加载中……');
        $.ajaxFileUpload({
            type: "post",
            fileElementId: "fileupload1",
            secureuri: false,
            dataType: 'text',
            url: "/communal/uploadBatch",
            // data:fileinfo,
            async: false,
            success: function (data) {
                var data = JSON.parse(data);
                var val = data.data.sysid;
                $("#taxproof_proof1").attr("value", val);
                if (data.code === "200") {
                    $('.warning>.title>em').html('上传成功');
                } else {
                    $('.warning>.title>em').html('上传失败');
                }
            },
            error: function (data) {
                alert("佐证材料上传失败 ！！请联系管理员");
            }
        });
    });

    /**
     * 被督查单位上传材料
     */
    $("#btn-upload2").click(function () {
        var fileval = $("#fileupload2").val();
        if (fileval == null || fileval == "") {
            alert("未选择任何文件");
            return;
        }
        $(".shade").fadeIn(100);
        $(".warning").fadeIn(100);
        $('.la-square-jelly-box').show();
        showShade();
        //警告框自定义内容
        $('.warning>.title>em').html('加载中……');
        $.ajaxFileUpload({
            type: "post",
            fileElementId: "fileupload2",
            secureuri: false,
            dataType: 'text',
            url: "/communal/uploadBatch",
            // data:fileinfo,
            async: false,
            success: function (data) {
                var data = JSON.parse(data);
                var val = data.data.sysid;
                $("#taxproof_proof2").attr("value", val);
                if (data.code === "200") {
                    $('.warning>.title>em').html('上传成功');
                } else {
                    $('.warning>.title>em').html('上传失败');
                }
            },
            error: function (data) {
                alert("佐证材料上传失败 ！！请联系管理员");
            }
        });
    });

    //显示隐藏
    $(".clickMe_form").click(function () {
        if ($(this).text() === "历史记录∨") {
            $(this).next(".open-sibling").show(500);
            $(this).text("收起∧")
        } else if ($(this).text() === "收起∧") {
            $(this).next(".open-sibling").hide(500);
            $(this).text("历史记录∨");
        }
    });
    jQuery(function ($) {
        $('.date-picker').datepicker({
            inline: true,
            format: "yyyymmdd",
            autoclose: true,
            todayHighlight: true,
            language: 'cn'
        }).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });
        var nodeSysId = '${nodeSysId}';
        var nodeStatus;
        $.ajax({
            type: "GET",
            url: "/api/nodes/checkNodeIsFinished",
            dataType: "json",
            data: {nodeSysId: nodeSysId},
            success: function (model) {
                if (model.code == "200") {
                    if (model.data) {
                        //节点已完成
                        nodeStatus = "1";
                        $('#supervision-Result').val("当前督查的项目节点:已完成");
                    } else {
                        //节点未完成
                        nodeStatus = "0";
                        $('#supervision-Result').val("当前督查的项目节点:未完成");
                    }
                } else {
                    console.log("数据错误，没有该节点！")
                }
            },
            error: function (model) {
            }
        });
        $.ajax({
            type: "GET",
            url: "/api/nodes/checkNodeIsFinished",
            dataType: "json",
            data: {nodeSysId: nodeSysId},
            success: function (model) {
                if (model.code == "200") {
                    if (model.data) {
                        //节点已完成
                        nodeStatus = "1";
                        $('#resp-Result').val("当前督查的项目节点:已完成");
                    } else {
                        //节点未完成
                        nodeStatus = "0";
                        $('#resp-Result').val("当前督查的项目节点:未完成");
                    }
                } else {
                    console.log("数据错误，没有该节点！")
                }
            },
            error: function (model) {
            }
        });

        $(".downloadFile").each(function () {
            if (isEmpty($(this).data("id"))) {
                $(this).attr("style", "display:none;");
            }
        });
    });

    $("#task-methon-id").change(function () {
        var change = $("#task-methon-id").val();
        if (change == 'AA') {
            $("#fileupload").removeAttr("required");
        } else {
            $("#fileupload").attr("required", true);
        }
    })

</script>